package com.kkd.kkdapp.utils;

import java.text.DecimalFormat;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Tools {

	public static String intOrDouble(double raw) {
		DecimalFormat df = new DecimalFormat("###.##");
		String result = df.format(raw);
		LogUtil.e("result", result);
		return result;
	}

	public static int calculationStringLenght(String st) {

		int lenght = 0;
		Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
		for (int i = 0; i < st.length(); i++) {
			Matcher m = p.matcher(st.substring(i, i + 1));
			if (m.matches()) {
				lenght = lenght + 2;
			} else {
				lenght = lenght + 1;
			}
		}

		return lenght;
	}

	public static boolean judgeStringQualified(String st) {
		boolean stAccord = true;
		Pattern p = Pattern.compile("[^a-zA-Z0-9\u4E00-\u9FA5_]");
		for (int i = 0; i < st.length(); i++) {
			Matcher m = p.matcher(st.substring(i, i + 1));
			if (m.matches()) {
				stAccord = false;
			}
		}
		return stAccord;
	}
}
